package com.jade.common.utils.file;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

@Component
public class CallPython {
	private static final Logger log = LoggerFactory
			.getLogger(CallPython.class);
	
	@Value("${datax.binPatch:F:\\DataX\\target\\datax\\datax\\bin}")
	public String BinPatch;
	
//    windowcmd = "cmd /c python datax.py D:\\Software\\install\\Environment\\DataX\\datax\\quartz\\mysql2mysql.json";

	
	/**
	 * 入参是命令行  ps windowcmd = "cmd /c python datax.py D:\\Software\\install\\Environment\\DataX\\datax\\quartz\\mysql2mysql.json";
	 * @param windowcmd
	 */
	public void callPython(String windowcmd ){
		try {
			log.info("start");
            log.info(windowcmd);
            //.exec("你的命令",null,new File("datax安装路径"));
            Process pr = Runtime.getRuntime().exec(windowcmd,null,new File("BinPatch"));
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
            	log.info(line);
            }
            in.close();
            pr.waitFor();
            log.info("end");
        } catch (Exception e) {
            e.printStackTrace();
        }

	}
}
